//
//  ThirdLoginView.m
//  backpack
//
//  Created by wj on 16/6/8.
//  Copyright © 2016年 wujian. All rights reserved.
//

#import "ThirdLoginView.h"

@interface ThirdLoginView()



@end

@implementation ThirdLoginView

-(id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    
    if (self) {
        
        UILabel *titleLabel = [[UILabel alloc] init];
//        titleLabel.text = @"其他登录方式";
        titleLabel.font = MidFont;
        titleLabel.textColor = TextColor;
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIImageView *lineView = [[UIImageView alloc] init];
        lineView.image = [UIImage imageNamed:@"line"];
        [self addSubview:lineView];
        self.lineView = lineView;
        
        UIButton *qqButton = [[UIButton alloc] init];
        qqButton.tag = 1;
        [qqButton addTarget:self action:@selector(clickItem:)forControlEvents:UIControlEventTouchUpInside];
        [qqButton setBackgroundImage:[UIImage imageNamed:@"qq"] forState:UIControlStateNormal];
        [self addSubview:qqButton];
        self.qqButton = qqButton;
        
        UIButton *weChatButton = [[UIButton alloc] init];
        weChatButton.tag = 2;
        [weChatButton addTarget:self action:@selector(clickItem:)forControlEvents:UIControlEventTouchUpInside];
        [weChatButton setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:UIControlStateNormal];
        
        [self addSubview:weChatButton];
        self.weChatButton = weChatButton;
        
        UIButton *sinaButton = [[UIButton alloc] init];
        sinaButton.tag = 3;
        [sinaButton addTarget:self action:@selector(clickItem:)forControlEvents:UIControlEventTouchUpInside];
        [sinaButton setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:UIControlStateNormal];
        [self addSubview:sinaButton];
        self.sinaButton = sinaButton;
        
        
        
        [self setConstraints];
    }
    
    return self;
}



-(void)setConstraints{

    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self);
        
        make.top.mas_equalTo(self);
        
        make.height.mas_equalTo(20);
        
    }];
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self.titleLabel);
        
        make.height.mas_equalTo(1);
    }];
    
    
    [self.weChatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self);
        
        make.centerY.mas_equalTo(self.qqButton);
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(35);
        
        make.bottom.mas_equalTo(self).offset(-20);
        
    }];
    
    [self.qqButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.weChatButton.mas_left).offset(-30);
        
        
        
    }];
    
    
    
    [self.sinaButton mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(self.qqButton);

        make.left.mas_equalTo(self.weChatButton.mas_right).offset(30);
    }];
}

- (void)clickItem:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(loginView:didSelctedItem:)]) {
        [self.delegate loginView:self didSelctedItem:button.tag];
    }
}
@end
